<template>
    <div @touchmove = "changeSearch">
        <header class="header">
            <router-link to="/selectDistrict" slot="left" class="district">
                <span class="goback" @click.prevent="goback"> 返回 </span>
                <img src="../assets/images/icon_address.png" alt="">
                {{this.$store.state.district}}
                <span> > </span>
            </router-link>
            <input type="text" slot="right" class="search" placeholder="请输入商家或商品名称">
        </header>
        <!-- 导航栏部分开始 -->
        <nav>
            <ul class="navbar">
                <li v-for="(item,index) in navbar" :key="index">
                    <router-link :to="item.link" class="toAddress">
                        <i class="item-icons"></i>
                        <span class="item-title">{{item.title}}</span>
                    </router-link>
                </li>
            </ul>
        </nav>
        <!-- 导航栏部分结束 -->
        <h5>
            附近商家
        </h5>
        <mt-navbar v-model="selected" class="navbar">
            <div class="dropdown-toggle" id="comprehensive" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">综合排序<span class="caret"></span></div>
            <mt-tab-item id="2">销量最高</mt-tab-item>
            <mt-tab-item id="3">距离最近</mt-tab-item>
            <mt-tab-item id="4">筛选</mt-tab-item>
            <ul class="dropdown-menu" aria-labelledby="comprehensive" id="com_con">
                <div v-for="n in nav_items" :key="n+'xyz'">
                    <li class="options"><a href="javascript:;">{{n}}</a></li>
                    <li role="separator" class="divider"></li>
                </div>
            </ul>
        </mt-navbar>
        <mt-tab-container v-model="selected" class="navbar-content">
            <mt-tab-container-item id="2">
                <ul>
                    <li>
                        <router-link :to="'/detail/'+item.id" class="navbar-link" v-for="(item,index) in highest" :key="index">
                            <div class="navbar-con-top">
                                <img :src="item.src" alt="">
                                <div class="navbar-content-des">
                                    <div class="title">{{item.title}}</div>
                                    <div class="rating">
                                        <div class="rating-l">
                                            <span class="stars">
                                                <i class="glyphicon glyphicon-star" v-for="(n,i) in parseInt(item.score)" :key="i+'abc'"></i>
                                                <i class="glyphicon glyphicon-star-empty" v-for="(n,i) in (5 -parseInt(item.score))" :key="i+'xyz'"></i>
                                            </span>
                                            <span class="score">{{item.score}}</span>
                                            <span class="sale-amount">月售<i>{{item.sale_amount}}</i>+</span>
                                        </div>
                                        <div class="rating-r">
                                            <span class="time"> <em>{{item.time}}</em> 分钟</span>|
                                            <span class="distance">{{item.distance}}</span>
                                        </div>
                                    </div>
                                    <div class="price">
                                        起送<span class="start-price">{{item.start_price}}</span>
                                        <i class="sep">|</i>
                                        配送<span class="delivery-price">{{item.delivery_price}}</span>
                                        <i class="sep">|</i>
                                        人均<span class="average">{{item.average}}</span>
                                    </div>
                                </div>
                            </div>
                            <div class="navbar-con-bottom">
                                <div v-if="item.reduce.exist == 1" class="reduce"> <img src="../assets/images/reduce.png" alt=""> {{item.reduce.con}}</div>
                                <div v-if="item.discount.exist == 1" class="discount"> <img src="../assets/images/discount.png" alt=""> {{item.discount.con}}</div>
                                <div v-if="item.acquire.exist == 1" class="acquire"> <img src="../assets/images/acquire.png" alt="">{{item.acquire.con}} </div>
                            </div>
                        </router-link>
                    </li>
                </ul>
            </mt-tab-container-item>
            
            <mt-tab-container-item id="3">
                <ul>
                    <li>
                        <router-link :to="'/detail/'+item.id" class="navbar-link" v-for="(item,index) in closest" :key="index">
                            <div class="navbar-con-top">
                                <img :src="item.src" alt="">
                                <div class="navbar-content-des">
                                    <div class="title">{{item.title}}</div>
                                    <div class="rating">
                                        <div class="rating-l">
                                            <span class="stars">
                                                <i class="glyphicon glyphicon-star" v-for="(n,i) in parseInt(item.score)" :key="i+'abc'"></i>
                                                <i class="glyphicon glyphicon-star-empty" v-for="(n,i) in (5 -parseInt(item.score))" :key="i+'xyz'"></i>
                                            </span>
                                            <span class="score">{{item.score}}</span>
                                            <span class="sale-amount">月售<i>{{item.sale_amount}}</i>+</span>
                                        </div>
                                        <div class="rating-r">
                                            <span class="time"> <em>{{item.time}}</em> 分钟</span>|
                                            <span class="distance">{{item.distance}}</span>
                                        </div>
                                    </div>
                                    <div class="price">
                                        起送<span class="start-price">{{item.start_price}}</span>
                                        <i class="sep">|</i>
                                        配送<span class="delivery-price">{{item.delivery_price}}</span>
                                        <i class="sep">|</i>
                                        人均<span class="average">{{item.average}}</span>
                                    </div>
                                </div>
                            </div>
                            <div class="navbar-con-bottom">
                                <div v-if="item.reduce.exist == 1" class="reduce"> <img src="../assets/images/reduce.png" alt=""> {{item.reduce.con}}</div>
                                <div v-if="item.discount.exist == 1" class="discount"> <img src="../assets/images/discount.png" alt=""> {{item.discount.con}}</div>
                                <div v-if="item.acquire.exist == 1" class="acquire"> <img src="../assets/images/acquire.png" alt="">{{item.acquire.con}} </div>
                            </div>
                        </router-link>
                    </li>
                </ul>
            </mt-tab-container-item>

            <mt-tab-container-item id="4">
                <div class="features">商家特色(可多选)</div>
                <ul class="item_container">
                    <li v-for="(item,index) in features" :key="index">{{item}}</li>
                </ul>
                <div class="rotate">
                    <h5>明星餐厅(味道赞)</h5>
                    <section>
                        <router-link :to="'/detail/'+item.id" class="navbar-link star_store" v-for="(item,index) in stars" :key="index">
                            <div class="navbar-con-top">
                                <img :src="item.src" alt="">
                                <div class="navbar-content-des">
                                    <div class="title">{{item.title}}</div>
                                    <div class="rating">
                                        <div class="rating-l">
                                            <span class="stars">
                                                <i class="glyphicon glyphicon-star" v-for="(n,i) in parseInt(item.score)" :key="i+'abc'"></i>
                                                <i class="glyphicon glyphicon-star-empty" v-for="(n,i) in (5 -parseInt(item.score))" :key="i+'xyz'"></i>
                                            </span>
                                            <span class="score">{{item.score}}</span>
                                            <span class="sale-amount">月售<i>{{item.sale_amount}}</i>+</span>
                                        </div>
                                        <div class="rating-r">
                                            <span class="time"> <em>{{item.time}}</em> 分钟</span>|
                                            <span class="distance">{{item.distance}}</span>
                                        </div>
                                    </div>
                                    <div class="price">
                                        起送<span class="start-price">{{item.start_price}}</span>
                                        <i class="sep">|</i>
                                        配送<span class="delivery-price">{{item.delivery_price}}</span>
                                        <i class="sep">|</i>
                                        人均<span class="average">{{item.average}}</span>
                                    </div>
                                </div>
                            </div>
                            <div class="navbar-con-bottom">
                                <div v-if="item.reduce.exist == 1" class="reduce"> <img src="../assets/images/reduce.png" alt=""> {{item.reduce.con}}</div>
                                <div v-if="item.discount.exist == 1" class="discount"> <img src="../assets/images/discount.png" alt=""> {{item.discount.con}}</div>
                                <div v-if="item.acquire.exist == 1" class="acquire"> <img src="../assets/images/acquire.png" alt="">{{item.acquire.con}} </div>
                            </div>
                        </router-link>
                    </section>
                </div>
            </mt-tab-container-item>
        </mt-tab-container>
    </div>
</template>

<script>
export default {
  data: function() {
    return {
      selected: "2",
      nav_items:['综合排序','速度最快','评分最高','起送价最低','配送费最低','人均高到低','人均低到高'],
      navbar: [
        //当前页面自己的数据
        { title: "美食", link: "/" },
        { title: "美团超市", link: "/" },
        { title: "生鲜果蔬", link: "/" },
        { title: "美团专送", link: "/" },
        { title: "下午茶", link: "/takeoutfood" },
        { title: "汉堡披萨", link: "/" },
        { title: "小吃馆", link: "/" },
        { title: "家常菜", link: "/" },
        { title: "鲜花蛋糕", link: "" },
        { title: "品牌连锁", link: "" }
      ],
      closest:[],
      highest:[],
      stars:[],
      features:['品牌商家','0元起送','免配送费','跨天预订','新商家','支持开发票','点评高分']
    };
  },
  methods:{
      changeSearch(){
          if($(window).scrollTop() > $(".header").height()){
            //   console.log($(window).scrollTop());
            $(".district").hide(1000);
            
          }else {
            $(".district").show(1000);
          }
      },
      goback(){
        this.$router.go(-1);
      }
  },
  mounted() {
    // 精灵图的循环
    var icons = document.querySelectorAll(".item-icons");
    for (var i = 0; i < icons.length; i++) {
      if (i < 5) {
        icons[i].style.backgroundPosition = `-${17 + i * 82}px -14.5px`;
      } else {
        icons[i].style.backgroundPosition = `-${17 + (i - 5) * 82}px -94px`;
      }
    }
    if(this.$store.state.district == '永乐公园'){
        this.stars = [];
        this.$http.get("./data/yongle_highestsale.json")
        .then(res => {
            this.highest = res.data.list;
            this.stars.push(...res.data.list);
        });
        this.$http.get("./data/yongle_closest.json")
        .then(res => {
            this.closest = res.data.list;
            this.stars.push(...res.data.list);
        });
    }else if(this.$store.state.district == '万达广场 A 座'){
        this.stars = [];
        this.$http.get("./data/wanda_highestsale.json")
        .then(res => {
            this.highest = res.data.list;
            this.stars.push(...res.data.list);
        });
        this.$http.get("./data/wanda_closest.json")
        .then(res => {
            this.closest = res.data.list;
            this.stars.push(...res.data.list);
        });
    }
    // this.$http.get("./data/anshan_data.json");
  }
};
</script>
    
<style scoped>
i,
em {
  font-style: normal;
}
.header {
  display: flex;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  line-height: 50px;
  background: #1c1b20;
  z-index: 999;
}
.header .district {
  overflow: hidden;
  white-space: nowrap;
  width: 200px;
  text-overflow: ellipsis;
  margin-left: 15px;
  font-size: 16px;
  color: #fff;
}
.header .district .goback {
  background: inherit;
}
.district img {
  width: 16px;
  margin-top: -3px;
}
.header .search {
  flex: 1;
  margin-right: 15px;
  height: 30px;
  border-radius: 100px;
  border: 0;
  outline: 0;
  padding-left: 20px;
}
nav {
  height: 165px;
  margin-top: 60px;
  padding: 0 15px;
  background: #fff;
}

nav .navbar {
  display: flex;
  height: 165px;
  flex-wrap: wrap;
  align-content: center;
}
#comprehensive {
  width: 90px;
  height: 52px;
  line-height: 52px;
  margin-top: -2.5px;
  font-size: 15px;
  font-weight: 600;
  color: #333;
  text-align: center;
}
#com_con {
  width: 100%;
}
#com_con .options {
  height: 42px;
  line-height: 42px;
  padding-left: 15px;
  font-size: 14px;
  color: #333;
}
nav .navbar li {
  flex: 20%;
}

nav .navbar li:nth-child(-n + 5) {
  margin-bottom: 20px;
}

nav .navbar li a {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  font-size: 12px;
  color: #666;
}

nav .navbar li .item-icons {
  width: 46px;
  height: 45px;
  margin-bottom: 5px;
  background: url(../../data/img/navbar12.png) -18px -14.5px no-repeat;
}
h5 {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.4;
}
h5::before {
  content: "";
  height: 1px;
  width: 60px;
  background: #666;
  margin-right: 3px;
  transform-origin: 100% 50%;
  transform: scale(0.5);
  display: inline-block;
}

h5::after {
  content: "";
  height: 1px;
  width: 60px;
  background: #666;
  margin-right: 3px;
  transform-origin: 0 50%;
  transform: scale(0.5);
  display: inline-block;
}
.navbar-content {
  margin-left: 20px;
  margin-right: 20px;
  height: 700px;
}
.navbar-content .navbar-link {
  display: block;
  height: 135px;
}
.navbar-content .navbar-link .navbar-con-top {
  display: flex;
  height: 60px;
}
.navbar-content .navbar-link .navbar-con-top img {
  width: 76px;
}
.navbar-content .navbar-link .navbar-content-des {
  flex: 1;
  margin-left: 15px;
}
.navbar-content .navbar-content-des .title {
  font-size: 16px;
  color: #333;
  line-height: 1.4;
  white-space: nowrap;
  width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.navbar-content .navbar-content-des .rating {
  overflow: hidden;
  margin: 3px 0;
  font-size: 12px;
  color: #333;
}
.rating-l {
  float: left;
}

.rating-r {
  float: right;
}
.glyphicon-star {
  color: #ffd454;
}
.glyphicon-star-empty {
  margin-left: -3px;
}
.sale-amount {
  margin-left: 10px;
}
.price {
  font-size: 12px;
  color: #333;
}
.sep {
  opacity: 0.3;
}

.navbar-con-bottom {
  margin: 7px 0 0 91px;
  color: #666;
  font-size: 11px;
}
.navbar-con-bottom img {
  width: 15px;
  height: 15px;
  vertical-align: middle;
  margin-top: -3px;
}
.discount {
  margin: 5px 0;
}

.features {
  margin-bottom: 10px;
  color: #999;
  font-size: 13px;
  font-weight: 300;
}
.item_container {
  display: flex;
  flex-wrap: wrap;
}
.item_container li {
  width: 29.16%;
  color: #333;
  border: 1px solid #ccc;
  border-radius: 1px;
  text-align: center;
  font-weight: 400;
  line-height: 30px;
  margin-right: 4.16%;
  margin-bottom: 10px;
  box-sizing: border-box;
  font-size: 13px;
}
/* 旋转图片部分 */
.rotate {
  perspective: 1000px;
  margin-top: 37px;
}

section {
  position: relative;
  width: 330px;
  height: 130px;
  margin: 29px auto;
  transform-style: preserve-3d;
  /* 添加动画效果 */
  animation: rotate 10s linear infinite;
  background: url(../assets/images/store7.png) no-repeat;
}

section:hover {
  /* 鼠标放入section 停止动画 */
  animation-play-state: paused;
}

@keyframes rotate {
  0% {
    transform: rotateY(0);
  }
  100% {
    transform: rotateY(360deg);
  }
}

section .star_store {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: linear-gradient(to right, #ff9569 0%, #e92758 100%);
}

section .star_store:nth-child(1) {
  transform: rotateY(0) translateZ(300px);
  /* background: url(../assets/images/store1.png) no-repeat; */
}

section .star_store:nth-child(2) {
  /* 先旋转好了再 移动距离 */
  transform: rotateY(60deg) translateZ(300px);
  /* background: url(../assets/images/store2.png) no-repeat; */
}

section .star_store:nth-child(3) {
  /* 先旋转好了再 移动距离 */
  transform: rotateY(120deg) translateZ(300px);
  /* background: url(../assets/images/store3.png) no-repeat; */
}

section .star_store:nth-child(4) {
  /* 先旋转好了再 移动距离 */
  transform: rotateY(180deg) translateZ(300px);
  /* background: url(../assets/images/store5.png) no-repeat; */
}

section .star_store:nth-child(5) {
  /* 先旋转好了再 移动距离 */
  transform: rotateY(240deg) translateZ(300px);
  /* background: url(../assets/images/store6.png) no-repeat; */
}

section .star_store:nth-child(6) {
  /* 先旋转好了再 移动距离 */
  transform: rotateY(300deg) translateZ(300px);
  /* background: url(../assets/images/store7.png) no-repeat; */
}
</style>


